//
//  AnimationImageView.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/2.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "AnimationImageView.h"

@interface AnimationImageView()

@property (nonatomic, strong) UIBezierPath *path;

@end
@implementation AnimationImageView

- (void)doAddBuyCarAnimationWithDelegate:(id)delegate
{
    if (self.isAnimation) return;
    CAKeyframeAnimation *position = [CAKeyframeAnimation animation];
    position.keyPath = @"position";
    position.path = self.path.CGPath;
    position.calculationMode = @"cubic";
    
    CAKeyframeAnimation *scale = [CAKeyframeAnimation animation];
    scale.keyPath = @"transform.scale";
    scale.values = @[@1.0,@0.8,@0.7,@0.6,@0.5];
    
    CABasicAnimation *rotation = [CABasicAnimation animation];
    rotation.keyPath = @"transform.rotation";
    rotation.toValue = @(M_PI*2);
    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[position,scale,rotation];
    group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    group.duration = 0.5;
    group.removedOnCompletion = NO;
    group.fillMode = kCAFillModeForwards;
    group.delegate = delegate;
    [self.layer addAnimation:group forKey:nil];
    self.isAnimation = YES;
}
- (UIBezierPath *)path
{
    if (!_path) {
        _path = [UIBezierPath bezierPath];
        CGPoint startPoint = CGPointMake(ScreenW-0.35*ScreenW, ScreenH-35);
        CGPoint endPoint = CGPointMake(0.1*ScreenW, ScreenH-35);
        CGPoint controlPoint = CGPointMake((startPoint.x-endPoint.x)/2.0+endPoint.x+30, endPoint.y-280);
        [_path moveToPoint:startPoint];
        [_path addQuadCurveToPoint:endPoint controlPoint:controlPoint];
    }
    return _path;
}

@end
